from bcat.util.str import Str


class Utility(object):
    @staticmethod
    def string_to_bytes(string):
        return Str(string).to_bytes()

    @staticmethod
    def bytes_to_string(buf):
        return Str.from_bytes(buf)


    @staticmethod 
    def string_is_empty(s):
        return Str(s).is_empty_or_space()




import unittest
class TestUtility(unittest.TestCase):
    def test_string_is_empty(self):
        self.assertTrue(Utility.string_is_empty(None))

        self.assertTrue(Utility.string_is_empty(""))
        self.assertTrue(Utility.string_is_empty("   "))

        self.assertFalse(Utility.string_is_empty("hello"))

        s = "abcde"
        bytes_s  = s.encode('utf-8')

        self.assertEqual(bytes_s, Utility.string_to_bytes(s))
        self.assertEqual(s, Utility.bytes_to_string(bytes_s))

    #TODO:
    def test_log_color(self):
        pass
        #rlog = ColorLog.Red(logging).;
        #rlog.error();
        #rlog.debug();
        #rlog.warning();
    #TODO:
    def test_email(self):
        pass
        #Validator.email(s).is_ok();
        #Validator.string(s).all_digital();
    
if __name__ == '__main__':
    unittest.main(verbosity=2)

